/**
 * 
 */
package servlets;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;


/**
 * @author hozakan
 *
 */
public class GoToLogin extends BaseServlet {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 3582752466375543523L;
	private static final Logger LOGGER = Logger.getLogger(GoToLogin.class);

	@Override
	protected void specificDoGet(HttpServletRequest request,
			HttpServletResponse response) {
		String query = request.getQueryString();
		if (query != null) {
			query = query.substring(query.indexOf("=")+1, query.length());
			query = "/"+query;
		} else {
			query = "/index";
		}
		System.out.println("tête finale de query : "+query);
		request.getSession(false).setAttribute("redirect", query);
		try {
			request.getRequestDispatcher("/pages/login.jsp").forward(request, response);
		} catch (ServletException e) {
			LOGGER.error("Impossible de rediriger vers la page de login");
		} catch (IOException e) {
			LOGGER.error("La page de login n'a pas été trouvée à l'endroit indiqué");
		}
	}

	@Override
	protected void specificDoPost(HttpServletRequest request,
			HttpServletResponse response) {
		//No job to do
	}
}
